﻿using System;
using System.Collections.Generic;

namespace FinMkts
{
    //TODO: calendar arithmetic, e.g. add some buiness days to a date
    /// <summary>
    /// A calendar that records working and non-working (holiday) days
    /// </summary>
    public class BusinessCalendar
    {
        /// <example>
        /// New York or London
        /// </example>
        public string Name { get; set; }

        /// <summary>
        /// The <see cref="TimeZoneInfo">Time Zone</see> the calendar applies to.
        /// </summary>
        public TimeZoneInfo TimeZone { get; set; }
           
        //TODO: recurring events, e.g. xmas?
        /// <example>
        /// Closed all day on 25 Decmeber 2010
        /// </example>
        /// <example>
        /// Closed 9 am till 12 pm on 1 May 2010
        /// </example>
        public IEnumerable<string> Holidays { get; set; }
        
        /// <summary>
        /// Is the business day open at a particular point in time
        /// </summary>
        /// <param name="when">The point in time to test</param>
        /// <returns>TRUE if the business day is open, FALSE if the business day is closed</returns>
        public bool IsOpen(DateTimeOffset when)
        {
            return IsNormallyOpen(when) && !IsOnHoliday(when);
        }

        /// <summary>
        /// Is the business day closed at a particular point in time
        /// </summary>
        /// <param name="when">The point in time to test</param>
        /// <returns>TRUE if the business day is closed, FALSE if the business day is open</returns>
        public bool IsClosed(DateTimeOffset when)
        {
            return !IsNormallyOpen(when) || IsOnHoliday(when);
        }

        /// <summary>
        /// Is the business day normally open at a point in time (ignoring holidays)
        /// </summary>
        /// <param name="when">The point in time to test</param>
        /// <returns>TRUE if the business day is normally open, FALSE if the business day is normally closed</returns>
        public virtual bool IsNormallyOpen(DateTimeOffset when)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="when">The point in time to test</param>
        /// <returns>TRUE if there is a holiday at the point in time, otherwise FALSE</returns>
        public virtual bool IsOnHoliday(DateTimeOffset when)
        {
            throw new NotImplementedException();
        }
        
        public virtual DateTimeOffset NextOpens(DateTimeOffset when)
        {
            throw new NotImplementedException();            
        }

        public virtual DateTimeOffset NextCloses(DateTimeOffset when)
        {
            throw new NotImplementedException();            
        }
    }

    //class BusinessTimeSpan
    //{
    //    public double Amount { get; private set; }
    //    public BusinessTimeUnit Unit { get; private set; }
    //}

    //enum BusinessTimeUnit
    //{
    //    Minute,
    //    Hour,
    //    Day,
    //    Week,
    //    Month,
    //    Year,
    //}
}